from django.db import models


# 创建轮播图模型
class BannerModel(models.Model):
    image = models.ImageField(upload_to='banner', verbose_name='轮播图', null=True,
                              blank=True, help_text='轮播图大小为1920*720')
    name = models.CharField(max_length=150, verbose_name='轮播图名字')
    note = models.CharField(max_length=150, verbose_name='备注信息')
    link = models.CharField(max_length=150, verbose_name='轮播图广告地址')
    orders = models.IntegerField(verbose_name='显示顺序')
    is_show = models.BooleanField(verbose_name='是否上架', default=False)
    is_delete = models.BooleanField(verbose_name='逻辑删除', default=False)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间', null=True, blank=True)

    class Meta:
        db_table = 'ly_banner'
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.name


# 创建导航栏
class NavModel(models.Model):
    """"导航"""
    NAV_POSITION = (
        (0, 'top'),
        (1, 'footer')
    )
    name = models.CharField(max_length=50, verbose_name='导航名称')
    link = models.CharField(max_length=200, verbose_name='导航地址')
    opt = models.IntegerField(choices=NAV_POSITION, verbose_name='位置')
    orders = models.IntegerField(verbose_name='显示顺序')
    is_show = models.BooleanField(verbose_name='是否上架', default=False)
    is_delete = models.BooleanField(verbose_name='逻辑删除', default=False)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'ly_nav'
        verbose_name = '导航'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']

    def __str__(self):
        return self.name


